package com.challenge.smsdao.studentmanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.challenge.smsbase.Domain.BaseEntity;
import com.challenge.smsdao.actionmanage.domain.Action;
import com.challenge.smsdao.admin.domain.Role;
import com.challenge.smsdao.coursemanage.domain.Course;
import com.challenge.smsdao.dormitorymanage.domain.Dormitory;

import javax.persistence.*;
import java.util.List;

/**
 * shaoyunfei
 */
@Entity
public class Student extends BaseEntity<Long> {
    @Column
    private String number;
    @Column
    private String sex;
    @Column
    private String name;
    @Column
    private String password;
    @Column
    private String telephone;
    @JsonIgnoreProperties("studentList")
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "grade_id")
    private Grade grade;
    @JsonIgnoreProperties("students")
    @ManyToOne(cascade = {CascadeType.REFRESH},fetch = FetchType.EAGER)
    @JoinColumn(name = "dormitory_id")
    private Dormitory dormitory;
    @OneToOne
    @JoinColumn(name = "role_id",referencedColumnName = "id")
    private Role role;
    @JsonIgnoreProperties("studentList")
    @ManyToMany(mappedBy = "studentList")
    private List<Course> courseList;

    @JsonIgnoreProperties("studentList")
    @ManyToMany
    @JoinTable(name = "select_action",joinColumns = @JoinColumn(name = "action_id"),inverseJoinColumns = @JoinColumn(name = "student_id"))
    private List<Action> actionList;

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }


    public Grade getGrade() {
        return grade;
    }

    public void setGrade(Grade grade) {
        this.grade = grade;
    }

    public Dormitory getDormitory() {
        return dormitory;
    }

    public void setDormitory(Dormitory dormitory) {
        this.dormitory = dormitory;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public List<Course> getCourseList() {
        return courseList;
    }

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public List<Action> getActionList() {
        return actionList;
    }

    public void setActionList(List<Action> actionList) {
        this.actionList = actionList;
    }

    @Override
    public String toString() {
        return "Student{" +
                "number='" + number + '\'' +
                ", sex='" + sex + '\'' +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                '}';
    }
}
